package com.huatech.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.huatech.domain.UserDetail;
import com.huatech.service.UserInfoService;
/**
 * 
 * @author lihua_java@163.com
 *
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Autowired UserInfoService  userInfoService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    	UserDetail user =  userInfoService.findByUserName(username);
    	if (user == null) {
            throw new UsernameNotFoundException("用户名或密码错误");
        }
        return user.toUser();
    }
}
